import java.util.ArrayList;
import java.util.Scanner;

public class HW_5_countNum {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        Scanner sc=new Scanner(System.in);
        System.out.println("你要输入数字的个数:");
        int num=sc.nextInt();
        System.out.println("请输入数字:");
        for (int i = 0; i < num; i++) {
            list.add(sc.nextInt());
        }
        ArrayList<Integer> list1 = new ArrayList<>();
        list1.add(list.get(0));
        for (int i = 0; i < list.size(); i++) {
            if (isRepeat(list1, list.get(i))) {
                continue;
            }
            list1.add(list.get(i));
        }
        for (int i = 0; i < list1.size(); i++) {
            System.out.println(list1.get(i)+"出现了"+countNum(list,list1.get(i))+"次");
        }
    }
    //判断集合中是否存在该数
    public static boolean isRepeat(ArrayList<Integer> list,int count){
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) == count) {
                return true;
            }
        }
        return false;
    }
    //计数
    public static int countNum(ArrayList<Integer> list,int count){
        int num=0;
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) == count) {
                num++;
            }
        }
        return num;
    }
}
